package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.xcity.db.entity.Invite;
import com.xcity.db.entity.Player;
import com.xcity.game.player.cache.PlayerCacheService;
import com.xcity.util.SimplePlayer;

import naga.x.App;
import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class InviteInfoResponse extends Response {

	public int num; // 当前已邀请玩家总数
	public int max; // 最多可邀请玩家数量
	public int state; // 奖励领取状态
	public List<SimplePlayer> invitees; // 被邀请者
	
	public InviteInfoResponse(int serial, int max, int state, List<Invite> invites) {
		super(serial);
		this.max = max;
		this.state = state;
		if (invites != null) {
			this.num = invites.size();
			this.invitees = new ArrayList<>(invites.size());
			PlayerCacheService pcs = App.getApp().getServiceManager().get(PlayerCacheService.class);
			for (Invite invite : invites) {
				Player player = pcs.find(invite.getInvitee());
				if (player != null) {
					this.invitees.add(new SimplePlayer(player));
				}
			}
		} else {
			this.invitees = Collections.emptyList();
		}
	}


}
